{% extends 'base.html' %}
{% load static %}
{% block content %}

{% if form.instance.id %}
        <h1>Edit Question</h1>
    {% else %}
        <h1>Create Question</h1>
    {% endif %}


<form method='POST'>
    <div class="form-group">
    {% csrf_token %}
    {{ form.as_p }}
    </div>
    {{formset.management_form}}
    <hr>
    <table class="table">
        <thead>
                    <tr>
                        <th>Text</th>
                        <th>Correct?</th>
                        <th>Delete?</th>
                    </tr>
                </thead>
        <tbody class="table">
            {% for form in formset %}
                {{ form.id }} <!--This is just for handling an error during save after editing -->
            	<tr >
            	<td> {{ form.detail }}{{ form.detail.errors }}</td>
            	<td>{{ form.correct }}</td>
                {% if form.instance.pk %}
            	   <td>{{ form.DELETE }}</td>
                {% else %}
                    <td></td>
                {% endif %}
            	</tr>
                {% endfor %}

        </tbody>
    </table>

	<input class="btn btn-success btn-lg" type="submit" name="Save" value="Save Question">
    {% if form.instance.id %}
        <input class="btn btn-warning btn-lg" type="submit" name="delete" value="Delete">
        <a class="btn btn-lg btn-danger" href="{% url 'Evaluator:question_details' form.instance.pk %}">Cancel</a>
    {% else %}
        <a class="btn btn-lg btn-danger" href="{% url 'Evaluator:profile' %}">Cancel</a>
    {% endif %}
	</div>
</form>
{% endblock %}
